package com.hhxy.login.interceptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @auther:Lu Yao
 * @date:2022/2/8
 * descript: https://blog.csdn.net/Mr_EvanChen/article/details/90295734
 **/
public class LoginInterceptor implements HandlerInterceptor {
       private final Logger logger= LoggerFactory.getLogger(LoginInterceptor.class);
       private  ThreadLocal<Object> threadLocal=new ThreadLocal<>();
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        logger.info("request请求地址path[{}] uri[{}]",request.getServletPath(),request.getRequestURI());
        //记录上下文，防止多线程冲突现象
        threadLocal.set(request.getServletContext());
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}